import filterSKLine from '@/filters/filterSKLine'
import CommonUtil from '@/common/common.util'
import Constant from '@/common/constant'
/**
 * 返回表格配置信息，其中包括对数据的处理
 * @param  {Array} data        表格数据
 * @param  {左右百分比} leftPerecent 左右百分比
 * @param  {Boolean} splitData   是否将数据按leftPerecent进行分割
 * @return {[type]}             [description]
 */
export default function (stock, splitData, leftPerecent) {
  // body...
  var data = filterSKLine(stock.K_LIST, splitData, leftPerecent)
  data.xName = stock.STOCK_NAME
  var yInterval = (data.max - data.min) / 4
  var option = {
    progressive: 150,
    grid: [
      {
        left: 0,
        width: (leftPerecent - 0.6) + '%',
        height: '89%'
      },
      {
        left: (leftPerecent - 0.1) + '%',
        width: (100 - leftPerecent + 0.5) + '%',
        height: '89%'
      }
    ],
    xAxis: [
      {
        data: data.x,
        axisLabel: {
          inside: false,
          interval: function (index) {
            if (index === 0 || index === data.x.length - 1) return true
            else return false
          },
          textStyle: {fontSize: 9},
          formatter: function (value, index) {
            if (index === 0) return '                      ' + value
            else if (index === data.x.length - 1) return value + '                      '
            else return ''
          }
        },
        splitLine: {
          show: false,
          interval: function (index) {
            if (index === 0 || index === parseInt(data.x.length / 2 - 1)) return true
            return false
          }
        }
      },
      {
        data: data.x1,
        axisLabel: {
          inside: false,
          interval: (index) => {
            if (index === data.x1.length - 1) return true
            else return false
          },
          textStyle: {fontSize: 9},
          formatter: function (value, index) {
            if (index === data.x1.length - 1) return value + '                      '
            else return ''
          }
        },
        splitLine: {
          show: false,
          interval: function (index) {
            if (index === 0 || index === (parseInt(data.x1.length / 2) - 1)) return true
            return false
          }
        }
      }
    ],
    yAxis: [
      {
        min: data.min,
        max: data.max,
        interval: yInterval
      },
      {
        min: data.min,
        max: data.max,
        interval: yInterval
      }
    ],
    series: [
      {
        data: data.y
      },
      {
        type: 'line'
      },
      {
        data: data.y1
      }
    ]
  }
  option = CommonUtil.extendObject(Constant.chartOption, option)
  return option
}
